package fr.maistre.SystemeMarché.Vue;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import org.jfree.data.xy.DefaultXYDataset;

import fr.maistre.SystemeMarché.Implementation.ReferenceMarket;

public class MarketDataSet extends DefaultXYDataset {

	private double max = Double.NEGATIVE_INFINITY;
	private double min = Double.POSITIVE_INFINITY;

	public MarketDataSet(HashMap<String, ReferenceMarket> marketValues) {

		for (String ref : marketValues.keySet()) {
			ReferenceMarket referenceMarket = marketValues.get(ref);
			if (Collections.min(referenceMarket.previousPrices) < min)
				min = Collections.min(referenceMarket.previousPrices);
			if (Collections.max(referenceMarket.previousPrices) > max)
				max = Collections.max(referenceMarket.previousPrices);
			this.addSeries(ref,
					previousPriceToData(referenceMarket.previousPrices));

		}
	}

	public MarketDataSet(String refName, List<Double> valeurs) {
		this.max = Collections.max(valeurs);
		this.min = Collections.min(valeurs);
		this.addSeries(refName, previousPriceToData(valeurs));
	}

	private double[][] previousPriceToData(List<Double> valeurs) {

		double[][] data = new double[2][valeurs.size()];
		for (int i = 0; i < valeurs.size(); i++) {

			data[0][i] = i;
			data[1][i] = valeurs.get(i);

		}

		return data;
	}

	public double getMinValue() {
		return this.min;
	}

	public double getMaxValue() {
		return this.max;
	}

}
